﻿using AutoMapper;
using MediatR;
using SmartTracking.API.Write.Application.Commands.Ewemating;
using SmartTracking.Domain.EWE;
using SmartTracking.ErrorCode;
using SmartTracking.Infrastructure.Interfaces;

namespace SmartTracking.API.Write.Application.CommandHandlers.Ewemating
{
    public class UpdateEwematingCommandHandler : IRequestHandler<UpdateEwematingCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Ewematings> eRep;
        private readonly IMapper mapper;

        public UpdateEwematingCommandHandler(IBaseRepository<Ewematings> eRep, IMapper mapper)
        {
            this.eRep = eRep;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(UpdateEwematingCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int>result=new ApiResult<int>();
            result.Code = ApiEnum.更新成功;
            result.Message = "更新成功";

            Ewematings info=mapper.Map<Ewematings>(request);
            info.EwematingUpTime = DateTime.Now;
            await eRep.UpdateAsync(info);   

            return await Task.FromResult(result);
        }
    }
}
